<?php
// +----------------------------------------------------------------------
// | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------
namespace app\admin\controller;

use \think\Controller;
use \think\Session;

class Permissions extends Controller
{
    /**
     * 检查用户是否登录
     * 检查用户访问的url在不在其角色组的权限范围内
     * 重写权限校验 By ganjn
     * @return [type] [description]
     */
    protected function _initialize()
    {
        //检查是否登录
        if (!Session::has('user')) {
            $this->redirect('admin/common/login');
        }
        // 错误模板动态定义
        config('dispatch_error_tmpl', APP_PATH . 'admin/view/errors/error_close.tpl');

    }

    /**
     * @param $code
     * @param $msg
     * @param $count
     * @param array $data
     * @param array $footer
     * @param $type
     */
    protected function responseAjax($code = 200, $msg = 'success', $count = 0, $data = [], $footer = [], $type = 'json')
    {
        return \think\Response::create(
            [
                'statusName' => 'code',
                'statusCode' => 200,
                'msgName'    => 'msg',
                'countName'  => 'count',
                'dataName'   => 'data',
                'code'       => $code,
                'msg'        => $msg,
                'count'      => $count,
                'data'       => $data,
                'footer'     => $footer,
            ],
            $type
        );
    }
}
